package com.haierp.controller.youzan;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.haierp.service.IOuterOrderService;
import com.haierp.service.xiaohongshu.IXiaohongshuService;
import com.haierp.service.youzan.IYouzanService;
import com.haierp.util.DateUtil;
import com.wangzhixuan.commons.base.BaseController;

@Controller
@RequestMapping("/youzanSynOrder")
public class YouzanSynOrderController extends BaseController {
	@Autowired
	private IYouzanService youzanService;
	
	@Autowired
	private IOuterOrderService outerOrderService;

	@Autowired
	private IXiaohongshuService xiaohongshuService;

	@RequestMapping("/youzanTradesAdd")
	@ResponseBody
	public void youzanTradesAdd() {
		List<Long> outOrderIdList = youzanService.youzanTradesAdd(DateUtil.parseDate("2017-06-25 12:00:00"), DateUtil.parseDate("2017-06-25 23:59:59"));
		System.out.println("======>" + outOrderIdList.size());
		if(outOrderIdList.size() > 0) {
			//生成子订单并配货
			outOrderIdList.forEach(erpOrderId -> {
				outerOrderService.review(erpOrderId,"YZ");
			});
		}
	}
	@RequestMapping("/xiaohongshuTradesAdd")
	@ResponseBody
	public void xiaohongshuTradesAdd() {
		List<Long> outOrderIdList = xiaohongshuService.xiaohongshuTradesAdd(DateUtil.parseDate("2018-07-07 00:00:00"), DateUtil.parseDate("2018-07-07 23:59:59"),"SL");
		System.out.println("======>" + outOrderIdList.size());
		if(outOrderIdList.size() > 0) {
			//生成子订单并配货
			outOrderIdList.forEach(erpOrderId -> {
				outerOrderService.review(erpOrderId,"XHSL");
			});
		}
	}
	
	//有赞售罄商品下架
	@RequestMapping("/youzanSaleOutItemToDelisting")
	@ResponseBody
	public void youzanSaleOutItemToDelisting() {
		youzanService.youzanSaleOutItemToDelisting();
	}
	
	public static void main(String[] args) {
		System.out.println(new Date());
		
		Date test = DateUtil.getDateByCalculate(new Date(), Calendar.HOUR_OF_DAY, 3);
		System.out.println(test);
	}
}
